﻿package Component {
	import Map.Block;
	import Map.BonusType;
	import flash.display.MovieClip;
	import Component.BonusBlocks.*;
	import Component.BonusPerms.BonusPerm;
	
	public class BonusBlock extends Block {
		
		private var _bonus:BonusBlock_Item;		
		public function set bonus(_bonus:BonusBlock_Item) {
			remove();
			// attach new bonus
			this._bonus = _bonus;
			addChild(_bonus);
			// swap depth
			this.swapChildrenAt(1,2);
		}
		
		public function BonusBlock() {
			_bonus = null;
		}
		
		public override function initialize(x:uint,y:uint) {
			super.initialize(x,y);
		}
		
		public function reset() {
			remove();
			_bonus = null;
		}
		
		private function remove() {
			// remove old bonus
			if(this._bonus != null)
				if(contains(_bonus))
					this.removeChild(this._bonus);
		}
		
		public function drop() {
			var bonus:BonusPerm = _bonus._base.drop();
			_bonus._base.remove();
			// copy the position of the block
			bonus.setPosition(pos_x,pos_y);
			bonus.visible = true;
		}
		
		public override function destroy() {
			super.destroy();
			if(this._bonus != null)
				_bonus._base.remove();
		}
		
		public override function onMapReset() {
			visible = false;
		}
		
	}
	
}
